//
//  FollowfanfavoritesViewController.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/9/20.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "FollowfanfavoritesViewController.h"

#import "CollectionmeetingCenterViewController.h"//收藏
#import "CollectionoforiginalmindViewController.h"
#import "Mycollect.h"
#import "MyPersonalfansTableViewCell.h"//关注
#import "MyPersonalattentioTableViewCell.h"//粉丝
#import "CloseMyTableViewCell.h"//亲密

@interface FollowfanfavoritesViewController ()<SGPageTitleViewDelegate, SGPageContentViewDelegate,UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UISearchDisplayDelegate>
{
    Mycollect * collect;//收藏
    
}

@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentView *pageContentView;
@property (nonatomic, strong) UITableView * tableViewPF;
@property (nonatomic, strong) UIView * viewScroll;//搜索条背景


@end

@implementation FollowfanfavoritesViewController

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    switch (self.inter) {
            
        case 100000:
            [self setCloseMyTableViewCellUp];
            NSLog(@"点击100000进入界面");
            break;
        case 100001:
            [self setPersonalattentionView];
            break;
            
        case 100002:
            [self setTableViewPersonalfansView];
            NSLog(@"点击100002进入界面");
            break;
            
        case 100003:
            [self setMycollectView];
            NSLog(@"点击100003进入界面");
            break;
        default:
            break;
    }
    
    
    self.view.backgroundColor=[UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1];
    
    //初始化视图  --会议 脑暴 收藏 记录
    
    [self setPublishedRecordView];
}

#pragma mark - 收藏
- (void)setMycollectView{
    collect = [[Mycollect alloc] initWithFrame:self.view.bounds];
    self.title = @"收藏";
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.translucent = YES;
    //    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg"]forBarMetrics:UIBarMetricsDefault];
    //返回按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, kWidthScale(15),kHeightScale(20));
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBarBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    [self.view addSubview:collect];
}
- (void)leftBarBtnClicked:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)setPublishedRecordView{
    
    CollectionmeetingCenterViewController * mettingView=[[CollectionmeetingCenterViewController alloc] init];
    CollectionoforiginalmindViewController * imaginationView=[[CollectionoforiginalmindViewController alloc] init];
    NSArray *childArr = @[imaginationView,mettingView];
    
    /// pageContentView
    CGFloat contentViewHeight = self.view.frame.size.height ;
    self.pageContentView = [[SGPageContentView alloc] initWithFrame:CGRectMake(0, kHeightScale(0), self.view.frame.size.width, contentViewHeight) parentVC:self childVCs:childArr];
    _pageContentView.delegatePageContentView = self;
    _pageContentView.backgroundColor=[UIColor redColor];
    [collect addSubview:_pageContentView];
    
    NSArray *titleArr = @[@"创想", @"会议"];
    /// pageTitleView
    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, kHeightScale(54), self.view.frame.size.width,kHeightScale(44)) delegate:self titleNames:titleArr];
    [collect addSubview:_pageTitleView];
    _pageTitleView.selectedIndex = 0;
    _pageTitleView.titleColorStateNormal = [UIColor lightGrayColor];
    _pageTitleView.titleColorStateSelected = [UIColor blackColor];
    _pageTitleView.indicatorColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg"]];
    _pageTitleView.indicatorLengthStyle = SGIndicatorLengthStyleEqual;
}
- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentView setPageCententViewCurrentIndex:selectedIndex];
}
- (void)pageContentView:(SGPageContentView *)pageContentView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    [self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}
#pragma mark -粉丝
- (void)setTableViewPersonalfansView{
    
    _tableViewPF=[[UITableView alloc] initWithFrame:CGRectMake(0, kHeightScale(72), UIScreenWidth, UIScreenHeight) style:UITableViewStylePlain];
    _tableViewPF.delegate=self;
    _tableViewPF.dataSource=self;
    [self.view addSubview:_tableViewPF];
    self.title = @"粉丝";
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.translucent = YES;
    //    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg"]forBarMetrics:UIBarMetricsDefault];
    //返回按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    leftBtn.frame = CGRectMake(0, 0, kWidthScale(15),kHeightScale(20));
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBarBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.tableViewPF.separatorStyle = UITableViewCellSeparatorStyleNone;// 去掉所有cell的分割线
}



#pragma mark -关注
- (void)setPersonalattentionView{
    
    _tableViewPF=[[UITableView alloc] initWithFrame:CGRectMake(0, kHeightScale(65), UIScreenWidth, UIScreenHeight) style:UITableViewStylePlain];
    _tableViewPF.delegate=self;
    _tableViewPF.dataSource=self;
    [self.view addSubview:_tableViewPF];
    self.title = @"关注";
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.translucent = YES;
    //    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg"]forBarMetrics:UIBarMetricsDefault];
    //返回按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    leftBtn.frame = CGRectMake(0, 0, kWidthScale(15),kHeightScale(20));
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBarBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    //搜索条
    _viewScroll=[[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(45))];
    _viewScroll.backgroundColor=[UIColor orangeColor];
    self.tableViewPF.tableHeaderView = _viewScroll;
    self.tableViewPF.separatorStyle = UITableViewCellSeparatorStyleNone;// 去掉所有cell的分割线
}


#pragma mark -亲密
- (void)setCloseMyTableViewCellUp
{
    _tableViewPF=[[UITableView alloc] initWithFrame:CGRectMake(0, kHeightScale(72), UIScreenWidth, UIScreenHeight) style:UITableViewStylePlain];
    _tableViewPF.delegate=self;
    _tableViewPF.dataSource=self;
    [self.view addSubview:_tableViewPF];
    self.title = @"亲密关系";
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.translucent = YES;
    //    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg"]forBarMetrics:UIBarMetricsDefault];
    //返回按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    leftBtn.frame = CGRectMake(0, 0, kWidthScale(15),kHeightScale(20));
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBarBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
}


//返回每个分区的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section==0) {
        return 3;//第一分区
    } else {
        return 3;//第二分区（按数据展示）
    };
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //关注
    if (self.inter == 100001) {
        
        static NSString * str=@"biao";
        MyPersonalfansTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (!cell) {
            cell=[[MyPersonalfansTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
        }
        if (indexPath.row == 2) {
            cell.lineLabel.hidden = YES;
        } else {
            cell.lineLabel.hidden = NO;
        }
        return cell;
    }
    //粉丝
    if (self.inter == 100002)
    {
        static NSString * str=@"biaoF";
        MyPersonalattentioTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (!cell) {
            cell=[[MyPersonalattentioTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
        }
        if (indexPath.row == 2) {
            cell.lineLabel.hidden = YES;
        } else {
            cell.lineLabel.hidden = NO;
        }
        return cell;
    }
    //亲密
    if (self.inter == 100000)
    {
        static NSString * str=@"biaoQ";
        CloseMyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (!cell) {
            cell=[[CloseMyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
        }
        return cell;
    }
    
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    //亲密
    if (self.inter == 100000)
    {
        if (section == 0)
        {
            return kHeightScale(31);
        }
        else
        {
            return kHeightScale(25);
        }
    }
    //关注
    if (self.inter==100001)
    {
        if (section == 0)
        {
            return kHeightScale(34);
        }
        else
        {
            return kHeightScale(25);
        }
    }
    //粉丝
    if (self.inter == 100002)
    {
        return kHeightScale(25);
    }
    return 0;
}
//自定义标题
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //亲密
    if (self.inter==100000)
    {
        UIView *view = [UIView new];
        NSArray *arr = @[@"管理员",@"全部"];
        if (section == 0)
        {
            UILabel * lab2 = [[UILabel alloc]init];
            lab2.textAlignment = 0;
            lab2.font = [UIFont fontWithName:@ "Arial" size:kWidthScale(12)];
            lab2.textColor = [UIColor colorWithHexString:@"#666666"];
            lab2.text = arr[section];
            [view addSubview:lab2];
            lab2.sd_layout
            .centerYEqualToView(view)
            .leftSpaceToView(view, kWidthScale(15))
            .widthIs(kWidthScale(100))
            .autoHeightRatio(0);
            UILabel * labLine =[[UILabel alloc] init];
            labLine.backgroundColor=[UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1];
            [view addSubview:labLine];
            labLine.sd_layout
            .bottomSpaceToView(view, kHeightScale(0))
            .leftSpaceToView(view, 0)
            .rightSpaceToView(view, 0)
            .heightIs(kHeightScale(1));
            
            view.backgroundColor = [UIColor whiteColor];
        }
        else if (section == 1)
        {
            UILabel * lab2 = [[UILabel alloc]init];
            lab2.textAlignment = 0;
            lab2.font = [UIFont fontWithName:@ "Arial" size:kWidthScale(12)];
            lab2.textColor = [UIColor colorWithHexString:@"#666666"];
            lab2.text = arr[section];
            [view addSubview:lab2];
            lab2.sd_layout
            .centerYEqualToView(view)
            .leftSpaceToView(view, kWidthScale(15))
            .widthIs(kWidthScale(100))
            .autoHeightRatio(0);
            view.backgroundColor = [UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1];
            
        }
        //创建一个手势进行点击，这里可以换成button
        
        UIButton * but = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(38))];
        but.tag = 300+section;
        but.backgroundColor = [UIColor clearColor];
        [but addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:but];
        return view;
    }
    //关注
    if (self.inter==100001)
    {
        UIView *view = [UIView new];
        NSArray *arr = @[@"热门关注",@"全部关注"];

        if (section == 0)
        {
            UILabel * lab2 = [[UILabel alloc]init];
            lab2.textAlignment = 0;
            lab2.font = [UIFont fontWithName:@ "Arial" size:kWidthScale(12)];
            lab2.textColor = [UIColor colorWithHexString:@"#666666"];
            lab2.text = arr[section];
            [view addSubview:lab2];
            lab2.sd_layout
            .centerYEqualToView(view)
            .leftSpaceToView(view, kWidthScale(15))
            .widthIs(kWidthScale(100))
            .autoHeightRatio(0);
            UIButton * toggle = [[UIButton alloc] init];
            [toggle setTitle:@"换一换" forState:UIControlStateNormal];
            [toggle setTitleColor:[UIColor colorWithHexString:@"0095e2"] forState:UIControlStateNormal];
            toggle.titleLabel.font=[UIFont systemFontOfSize:kWidthScale(12)];
            [view addSubview:toggle];
            toggle.sd_layout
            .centerYEqualToView(view)
            .rightSpaceToView(view,kWidthScale(15))
            .widthIs(kWidthScale(40))
            .autoHeightRatio(0);
            UILabel * labLine =[[UILabel alloc] init];
            labLine.backgroundColor=[UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1];
            [view addSubview:labLine];
            labLine.sd_layout
            .bottomSpaceToView(view, kHeightScale(0))
            .leftSpaceToView(view, 0)
            .rightSpaceToView(view, 0)
            .heightIs(kHeightScale(1));
            
            view.backgroundColor=[UIColor whiteColor];
        }
        else if (section == 1)
        {
            UILabel * lab2 = [[UILabel alloc]init];
            lab2.textAlignment = 0;
            lab2.font = [UIFont fontWithName:@ "Arial" size:kWidthScale(12)];
            lab2.textColor = [UIColor colorWithHexString:@"#666666"];
            lab2.text = arr[section];
            [view addSubview:lab2];
            lab2.sd_layout
            .centerYEqualToView(view)
            .leftSpaceToView(view, kWidthScale(15))
            .widthIs(kWidthScale(100))
            .autoHeightRatio(0);
            view.backgroundColor = [UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1];

        }
        
        //创建一个手势进行点击，这里可以换成button
        
        UIButton * but = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(38))];
        but.tag = 300+section;
        but.backgroundColor = [UIColor clearColor];
        [but addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:but];
        return view;
    }
    //粉丝
    if (self.inter==100002)
    {
        
        
        UIView *view = [UIView new];
        NSArray *arr = @[@"经常了解",@"全部粉丝"];
        
        
        
        if (section == 0)
        {
            UILabel * lab2 = [[UILabel alloc]init];
            lab2.textAlignment = 0;
            lab2.font = [UIFont fontWithName:@ "Arial" size:kWidthScale(12)];
            lab2.textColor = [UIColor colorWithHexString:@"#666666"];
            lab2.text = arr[section];
            [view addSubview:lab2];
            lab2.sd_layout
            .centerYEqualToView(view)
            .leftSpaceToView(view, kWidthScale(15))
            .widthIs(kWidthScale(100))
            .autoHeightRatio(0);
            UILabel * labLine =[[UILabel alloc] init];
            labLine.backgroundColor=[UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1];
            [view addSubview:labLine];
            labLine.sd_layout
            .bottomSpaceToView(view, kHeightScale(0))
            .leftSpaceToView(view, 0)
            .rightSpaceToView(view, 0)
            .heightIs(kHeightScale(1));
            
            view.backgroundColor = [UIColor whiteColor];
        }
        else if (section == 1)
        {
            UILabel * lab2 = [[UILabel alloc]init];
            lab2.textAlignment = 0;
            lab2.font = [UIFont fontWithName:@ "Arial" size:kWidthScale(12)];
            lab2.textColor = [UIColor colorWithHexString:@"#666666"];
            lab2.text = arr[section];
            [view addSubview:lab2];
            lab2.sd_layout
            .centerYEqualToView(view)
            .leftSpaceToView(view, kWidthScale(15))
            .widthIs(kWidthScale(100))
            .autoHeightRatio(0);
            view.backgroundColor = [UIColor colorWithRed:242.0/255.0 green:242.0/255.0 blue:242.0/255.0 alpha:1];
            
        }
        //创建一个手势进行点击，这里可以换成button
        
        UIButton * but = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, UIScreenWidth, kHeightScale(38))];
        but.tag = 300+section;
        but.backgroundColor = [UIColor clearColor];
        [but addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:but];
        return view;
    }

    return nil;
}
-(void)click:(UIButton *)sender
{
    UIButton *btn = (UIButton *)sender;
    
    switch (btn.tag) {
        case 300:
            
            break;
            
        case 301:
            NSLog(@"点击了评论人数");
            break;
            
        default:
            break;
    }
}

//设置对应位置的cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return kHeightScale(72);
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
